package com.gscitysfy.cus.drain.modules.command.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.gscitysfy.cloudfrmwk.assistant.domain.Result;
import com.gscitysfy.cus.drain.annotations.DictTranslation;
import com.gscitysfy.cus.drain.annotations.FieldParam;
import com.gscitysfy.cus.drain.constants.DicConstant;
import com.gscitysfy.cus.drain.modules.command.dto.IPageDto;
import com.gscitysfy.cus.drain.modules.command.dto.SchemeManageAuditDto;
import com.gscitysfy.cus.drain.modules.command.dto.SchemeManageDto;
import com.gscitysfy.cus.drain.modules.command.service.ISchemeManageService;
import com.gscitysfy.cus.drain.modules.command.vo.SchemeManageQuery;
import com.gscitysfy.cus.drain.modules.inspection.vo.DrainInspectionMnProblemVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * <p>
 * 调度方案管理 前端控制器
 * </p>
 *
 * @author Administrator
 * @since 2022-10-20 18:58:46
 */
@Tag(name = "指挥调度 -> 调度方案管理")
@AllArgsConstructor
@RestController
@RequestMapping(value = "/scheme")
public class SchemeManageController {

    private final ISchemeManageService iSchemeManageService;
    @Resource
    private HttpServletResponse httpServletResponse;
    @Operation(summary = "获取调度方案管理列表")
    @DictTranslation({
            @FieldParam(dictType = DicConstant.COMMAND_SCHEME_CATEGORY, targetField = "schemeCategory")
    })
    @GetMapping("/list")
    public Result<IPage<SchemeManageDto>> pageList(IPageDto page, SchemeManageQuery query) {
        return Result.content(iSchemeManageService.fetchPage(page.getPage(), query));
    }

    @Operation(summary = "新增调度方案管理")
    @PostMapping
    public Result<Boolean> save(@RequestBody SchemeManageDto dto) {
        return Result.content(iSchemeManageService.saveOrUpdate(dto));
    }

    @Operation(summary = "修改调度方案管理")
    @PutMapping
    public Result<Boolean> update(@RequestBody SchemeManageDto dto) {
        return Result.content(iSchemeManageService.saveOrUpdate(dto));
    }

    @Operation(summary = "删除调度方案管理")
    @PutMapping(value = "/delete")
    public Result<Boolean> delete(@RequestBody List<Long> idList) {
        return Result.content(iSchemeManageService.delete(idList));
    }


    @Operation(summary = "是否启用调度方案管理")
    @PutMapping(value = "/enable/{cmKid}")
    public Result<Boolean> enable(@PathVariable Long cmKid) {
        return Result.content(iSchemeManageService.enable(cmKid));
    }

    @Operation(summary = "审核调度方案管理")
    @PutMapping(value = "/audit")
    public Result<Boolean> audit(@RequestBody SchemeManageAuditDto dto) {
        return Result.content(iSchemeManageService.audit(dto));
    }


    @Operation(summary = "调度方案修改车辆")
    @PostMapping(value = "/saveSchemeCar")
    public Result<Boolean> saveSchemeCar(@RequestBody SchemeManageDto dto) {
        return Result.content(iSchemeManageService.saveSchemeCar(dto));
    }


    @Operation(summary = "调度方案修改队伍")
    @PostMapping(value = "/saveSchemeTeam")
    public Result<Boolean> saveSchemeTeam(@RequestBody SchemeManageDto dto) {
        return Result.content(iSchemeManageService.saveSchemeTeam(dto));
    }

    /**
     * 导出调度方案
     * @param dto
     */
    @GetMapping("/exportSchemeFile")
    @Operation(summary = "导出调度方案", description = "导出调度方案")
    public void exportSchemeFile( SchemeManageDto dto) throws IOException {
        this.iSchemeManageService.exportSchemeFile(httpServletResponse,dto);
    }
}
